package com.tasks.task01;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class NumberSortMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable>{
  private IntWritable intWritable = new IntWritable();
  @Override
  protected void map(LongWritable lineOffset,Text lineContent,Context context) throws IOException, InterruptedException {
    String lineStr =  lineContent.toString();
    if(lineStr == null || lineStr.length()<1)
      return;
    try{
      int result = Integer.parseInt(lineStr);
      intWritable.set(result);
      context.write(intWritable,NullWritable.get());
    }catch (NumberFormatException ex){
      return;
    }
  }
}
